package com.fengke.dao.admin.impl;

import java.sql.SQLException;
import java.util.List;

import com.fengke.dao.BaseDaoIbatis;
import com.fengke.dao.admin.AdminManager;
import com.fengke.dao.model.AdminModel;
import com.fengke.dao.model.AdminRoleModel;
import com.fengke.dao.model.RoleModel;

public class AdminManagerImpl extends BaseDaoIbatis implements AdminManager {

	public AdminModel researchAdminByLoginInfo(AdminModel adminModel) throws SQLException {
		@SuppressWarnings("unchecked")
		List<AdminModel> modelList = this.getSqlMapClientTemplate().queryForList("AdminRepository.researchAdminByLoginInfo", adminModel);
		if(modelList != null && modelList.size() > 0) {
			return modelList.get(0);
		}
		return null;
	}

	@Override
	public Integer researchAdminListSize(AdminModel adminModel) throws SQLException {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("AdminRepository.researchAdminModelListSize", adminModel);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AdminModel> researchAdminModelList(AdminModel adminModel, int offset, int limit) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("AdminRepository.researchAdminModelList", adminModel, offset, limit);
	}

	@Override
	public Integer checkAdminUsernameUnique(AdminModel adminModel) throws SQLException {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("AdminRepository.checkAdminUsernameUnique", adminModel);
	}

	@Override
	public Long createAdminModel(AdminModel adminModel) throws SQLException {
		return (Long) this.getSqlMapClientTemplate().insert("AdminRepository.createAdminModel", adminModel);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<RoleModel> researchRoleList(RoleModel roleModel) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("AdminRepository.researchRoleList", roleModel);
	}

	@Override
	public void createAdminRoleModel(AdminRoleModel adminRoleModel) throws SQLException {
		this.getSqlMapClientTemplate().insert("AdminRepository.createAdminRole", adminRoleModel);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AdminRoleModel> researchAdminRoleList(AdminRoleModel adminRoleModel) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("AdminRepository.researchAdminRoleList", adminRoleModel);
	}

	@Override
	public AdminModel researchAdminById(AdminModel adminModel) throws SQLException {
		return (AdminModel) this.getSqlMapClientTemplate().queryForObject("AdminRepository.researchAdminModelById", adminModel);
	}

	@Override
	public int deleteAdminRoleByAdminIds(List<String> list) throws SQLException {
		return this.getSqlMapClientTemplate().delete("AdminRepository.deleteAdminRoleByAdminIds", list);
	}
	
	@Override
	public int deleteAdminByIds(List<String> list) throws SQLException {
		return this.getSqlMapClientTemplate().delete("AdminRepository.deleteAdminModelByIds", list);
	}

	@Override
	public int updateAdminById(AdminModel adminModel) throws SQLException {
		return this.getSqlMapClientTemplate().update("AdminRepository.updateAdminModelById", adminModel);
	}

	@Override
	public int updateAdminLoginSuccessInfo(AdminModel adminModel) throws SQLException {
		return this.getSqlMapClientTemplate().update("AdminRepository.updateAdminLoginSuccessInfo", adminModel);
	}

	@Override
	public int updateAdminLoginFailureInfo(AdminModel adminModel) throws SQLException {
		return this.getSqlMapClientTemplate().update("AdminRepository.updateAdminLoginFailureInfo", adminModel);
	}
	
}
